package kunsch.bexp.transform;

import java.util.ArrayList;
import java.util.List;

import kunsch.bexp.Variable;

public class UserDefinedVariableOrderStrategy implements VariableOrderStrategy
{
	String[] variableStrings;
	
	public UserDefinedVariableOrderStrategy(String... variables)
	{
		this.variableStrings = variables;
	}
	
	@Override
	public List<Variable> order(List<Variable> variables)
	{
		List<Variable> orderedVariables = new ArrayList<Variable>();
		for(String varString : this.variableStrings)
		{
			for(Variable var : variables)
			{
				if(var.getDescription().equals(varString))
					orderedVariables.add(var);
			}
		}
		
		if(orderedVariables.size() == variables.size())
			return orderedVariables;
		else
			try
			{
				throw new Exception("given variable Strings in UserDefinedVariableOrderStrategy cant be found in Variable List");
			}
			catch (Exception e)
			{
				e.printStackTrace();
			}
		return null;
		
		
	}

}
